package bf.runner;

import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import bf.program.CompiledProgram;
import bf.program.Program;
import bf.program.State;
import bf.util.BrainfuckParser;

public class ParseCompileRunner {
	public static void main(String[] args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
		String filename = args[0];
		System.out.println("compile and run: " + filename);
		long time1 = System.currentTimeMillis();
		Program prog;
		try {
			prog = BrainfuckParser.parse(new FileReader(filename));
			prog.compile();
			prog.execute(new State());
//			Method method = compile.getMethod("execute", new Class[]{State.class});
//			method.invoke(null, new Object[]{new State()});
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		long time2 = System.currentTimeMillis();
		System.out.println();
		System.out.println(time2 - time1 + " ms");
	}
}
